<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ScanLog extends Model
{
    use HasFactory;
    
    /**
     * 指示模型是否应该被打上时间戳
     *
     * @var bool
     */
    public $timestamps = false;
    
    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'scanner_user_id',
        'car_owner_id',
        'scan_time',
        'call_made',
        'ip_address',
        'device_info',
    ];
    
    /**
     * The attributes that should be cast.
     *
     * @var array<string, string>
     */
    protected $casts = [
        'scan_time' => 'datetime',
        'call_made' => 'boolean',
    ];
    
    /**
     * 获取扫码的用户
     */
    public function scanner()
    {
        return $this->belongsTo(User::class, 'scanner_user_id');
    }
    
    /**
     * 获取被扫码的车主
     */
    public function carOwner()
    {
        return $this->belongsTo(CarOwner::class);
    }
}
